#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;


class compare{
public:
    bool operator()(pair<int,int> A,pair<int,int> B){
        return A.second<B.second; 
    }
};

class Solution {
public:
    
    vector<int> topKFrequent(vector<int>& nums, int k) {
        map<int,int> M;
        priority_queue<pair<int,int>,vector<pair<int,int>>,compare> T;
        for(int i = 0;i<nums.size();++i){
            ++M[nums[i]];
        }
        for(auto i = M.begin();i!=M.end();++i){
            T.push(*i);
        }
        vector<int> result;
        for(int i = 0;i<k;++i){
            result.push_back(T.top().first);
            T.pop();
        }
        return result;
    }
};

int main(){
    Solution S;
    vector<int> nums = {1,1,1,2,2,3,3,3,3};
    vector<int> result = S.topKFrequent(nums,2);
    return 0;
    
}